﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    assembly="KuaJing.Organization"
    namespace="KuaJing.Organization.Domain">

    <class name="OrganizationUnit" table="Organization_OrganizationUnit">
        <id name="Id" access="field.camelcase"
            column="OrganizationUnitId" type="Int32">
            <generator class="native" />
        </id>
        <version name="Version" access="field.camelcase" />

        <property name="Name" />
        <property name="ShortName" />
        <many-to-one name="Leader" class="Employee"
                     column="LeaderId" />
      
      <set name="Employees"  table="Organization_OrganizationUnit_Employee" cascade="save-update" >
        <key column="OrganizationId" foreign-key="FK_Organization_OrganizationUnit_OrganizationId_Organization_Employee_EmployeeId"></key>
        <many-to-many class="Employee" column="EmployeeId"></many-to-many>
      </set>
      
        <set name="Positions"  table="Organization_OrganizationUnit_Position" cascade="save-update" >
          <key column="OrganizationId" foreign-key="FK_Organization_OrganizationUnit_OrganizationId_Organization_Position_PositionId"></key>
          <many-to-many class="Position" column="PositionId"></many-to-many>
        </set>

      <property name="NamePath" access="field.camelcase" />
      <many-to-one name="Parent" class="OrganizationUnit"
             column="ParentId" />
      <set name="Children" cascade="all">
        <key column="ParentId" foreign-key="FK_Organzation_ParentId" />
        <one-to-many class="OrganizationUnit" />
      </set>
      
        <property name="CreatedTime" access="field.camelcase" />
        <property name="CreatedUserName" access="field.camelcase" />
        <property name="ModifiedTime" access="field.camelcase" />
        <property name="ModifiedUserName" access="field.camelcase" />
        <property name="AccessedTime" access="field.camelcase" />
        <property name="AccessedUserName" access="field.camelcase" />
        <property name="Memo" />
        <property name="IsInvalid" />
    </class>
</hibernate-mapping>
